<?php

class BaseHelper{
	
	//获取服务协议列表
	public static function GetXieYiList(){
		$list = Config('nawen.xieyi');
		$result = [];
		foreach($list as $one){
			list($title,$body) = self::GetXieYi($one);
			$result[] = [
				'name' => $one,
				'title' => $title,
				'body' => $body,
			];
		}
		return $result;
	}
	
	//获取服务协议
	public static function GetXieYi($name){
		$list = Config('nawen.xieyi');
		if(!in_array($name,$list)){
			__log('xieyi['.$name.'] not exists','xieyi');
			return ['',''];
		}
		$path = __DIR__ . '/../data/xieyi/' . $name . '.txt';
		$content = file_get_contents($path);
		$title = '';
		$body = '';
		
		$i = strpos($content,'<title>');
		$j = strpos($content,'</title>');
		
		if($i === false || $j===false || $i > $j){
			__log('xieyi['.$name.'] geshi cuowu','xieyi');
			return ['',''];
		}
		
		$title = substr($content,$i+7,$j-$i-7);
		$body = substr($content,$j+8);
		return [$title,$body];

	}
	

	
	
}